//
//  NSString+Check.m
//  CleanerAir_Project
//
//  Created by 付亚杰 on 16/6/12.
//  Copyright © 2016年 Beijing Colin El Internet. All rights reserved.
//

#import "NSString+Check.h"

@implementation NSString (Check)

+ (BOOL)isPhone:(NSString *)str{
    
    NSString * regex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
    
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch) {
        
//        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil];
//        
//        [alert show];
//        
        [ShowMessage showCenterViewMessage:@"请输入正确的手机号码"];
        return NO;
        
    }
    
    
    return YES;
}

+ (BOOL)isNumLetterAndChinese:(NSString *)string showMessage:(NSString *)showMessage{
    
    NSString *regex = @"[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    BOOL isTrue = ![pred evaluateWithObject: string];
    
    if (isTrue) {
        [ShowMessage showCenterViewMessage:showMessage];
    }
    
    return isTrue;
    
}

+ (BOOL)isMail:(NSString *)string{
    

    NSString *regex = @"[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    BOOL returnB = ![pred evaluateWithObject: string];
    
    if (returnB) {
        [ShowMessage showCenterViewMessage:@"请填写正确的邮箱"];
    }
    
    return returnB;
    
}

+ (BOOL)isPwd:(NSString *)string{
    
    NSString *regex = @"[a-zA-Z0-9][a-zA-Z0-9]*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    BOOL returnB = ![pred evaluateWithObject: string];
    
    if (returnB) {
        [ShowMessage showCenterViewMessage:@"密码只能由数字、字母组成"];
    }
    
    return returnB; 
}


+ (BOOL)passWordTextFileisExistSpace:(NSString *)str{
    
    NSRange aa = [str rangeOfString:@" "];
    
    if (aa.location == NSNotFound) {
        return NO;
    }else{
        return YES;
    }
}


@end
